package com.whq.thrift.api.web.admin.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DateFormatUtil {
	
	private static Log LOGGER = LogFactory.getLog(DateFormatUtil.class);
	
	public static Date formatToDate(String date) {
		String format = "MM/dd/yyyy";
		Date retValue = null;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			retValue = sdf.parse(date);
		} catch (ParseException e) {
			LOGGER.error("日期解析错误: ", e);
		}
		return retValue;
	}
	
	public static Date formatStringToFullDate(String date) {
		String format = "yyyy-MM-dd HH:mm:ss";
		Date retValue = null;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			retValue = sdf.parse(date);
		} catch (ParseException e) {
			LOGGER.error("日期解析错误: ", e);
		}
		return retValue;
	}
	
	public static String dateToString(Date date) {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String str=sdf.format(date);
		return str;
	}

}
